package cn.javase.http;

public enum ContentType {
    // 文本类型
    TEXT_PLAIN("text/plain"),
    TEXT_HTML("text/html"),
    TEXT_CSS("text/css"),
    TEXT_JAVASCRIPT("text/javascript"),

    // 图像类型
    IMAGE_JPEG("image/jpeg"),
    IMAGE_PNG("image/png"),
    IMAGE_GIF("image/gif"),
    IMAGE_SVG_XML("image/svg+xml"),

    // 应用程序类型
    APPLICATION_JSON("application/json"),
    APPLICATION_XML("application/xml"),
    APPLICATION_OCTET_STREAM("application/octet-stream"),
    APPLICATION_PDF("application/pdf"),
    APPLICATION_XHTML_XML("application/xhtml+xml"),
    APPLICATION_ZIP("application/zip"),

    // 多部分类型
    MULTIPART_FORM_DATA("multipart/form-data"),
    MULTIPART_MIXED("multipart/mixed");

    private final String contentType;

    ContentType(String contentType) {
        this.contentType = contentType;
    }

    public String getContentType() {
        return contentType;
    }

    @Override
    public String toString() {
        return contentType;
    }

    public static ContentType fromString(String contentType) {
        for (ContentType ct : values()) {
            if (ct.getContentType().equalsIgnoreCase(contentType)) {
                return ct;
            }
        }
        throw new IllegalArgumentException("Unknown content type: " + contentType);
    }
}